﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using PromoServer.Library.Data;

namespace PromoServer.Library.Entities
{
    public class Device : INotifyPropertyChanged
    {
        // Declare the property changed event 
        public event PropertyChangedEventHandler PropertyChanged;

        private PSData _psData;

        private Int32 _deviceID;
        public Int32 DeviceID { get { return _deviceID; } }

        private string _hostName;
        public string HostName { get { return _hostName; } }

        private string _displayName;
        public string DisplayName 
        {
            get
            {
                return _displayName;
            }
            set
            {
                _displayName = value;

                // Update display name in database
                _psData = new PSData();
                _psData.UpdateDisplayName(_deviceID, _displayName);

                // Call OnPropertyChanged whenever the property is updated
                OnPropertyChanged("DisplayName");
            }
        }

        public string DisplayLayout { get; set; }

        public int DisplayWidth { get; set; }

        public int DisplayHeight { get; set; }

        public string DisplayResolution
        {
            get
            {
                return DisplayWidth.ToString() + " x " + DisplayHeight.ToString();
            }
        }

        public Device(Int32 deviceID, string hostName, string displayName, string activeLayout, int displayWidth, int displayHeight)
        {
            _deviceID = deviceID;
            _hostName = hostName;
            _displayName = displayName;
            DisplayLayout = activeLayout;
            DisplayWidth = displayWidth;
            DisplayHeight = displayHeight;
        }

        // Create the OnPropertyChanged method to raise the event 
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}
